
sampler2D input : register(s0);
sampler2D blend : register(s1);
float mode : register(c0);
float4 main(float2 uv : TEXCOORD) : COLOR 
{ 
	float4 inputColor;
	inputColor = tex2D(input, uv);

	float4 blendColor;
	blendColor = tex2D(blend, uv);


	float4 resultColor;
	if(mode==1){//Multiply
	resultColor.a = inputColor.a; 
	// un-premultiply the blendColor alpha out from blendColor
	blendColor.rgb = clamp(blendColor.rgb / blendColor.a, 0, 1); 
	// apply the blend mode math
	// R = Base * Blend
	resultColor.rgb = blendColor.rgb * inputColor.rgb; 
	// re-multiply the blendColor alpha in to blendColor, weight inputColor according to blendColor.a
	resultColor.rgb = (1 - blendColor.a) * inputColor.rgb + resultColor.rgb * blendColor.a;
}
else if(mode==2)
{//Average
	resultColor.a = inputColor.a;

	// un-premultiply the blendColor alpha out from blendColor
	blendColor.rgb = clamp(blendColor.rgb / blendColor.a, 0, 1);


	// apply the blend mode math
	resultColor.rgb = (inputColor.rgb + blendColor.rgb) / 2;


	// re-multiply the blendColor alpha in to blendColor, weight inputColor according to blendColor.a
	resultColor.rgb = (1 - blendColor.a) * inputColor.rgb + resultColor.rgb * blendColor.a;
}
else{

}
	return resultColor;
}
